import Vue from 'vue'
import Router from 'vue-router'
import login from '@/views/login/index.vue'
import register from '@/views/register/index.vue'
import index from '@/views/index/index.vue'

Vue.use(Router)

const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

// Router.beforeEach((to,from,next) =>{
//   axios({
//     url: '/api/user?id=' + localStorage.getItem('Authorization'),
//     methods: 'get',
//     data: {
//       "token": localStorage.getItem('Authorization'),
//     }
//   }).then((res) => {
//       // 存储权限列表
//       store.commit('setList', res.data.data.routerLsit);
//       store.commit('setMenu', res.data.data.menuList);
//       // resolve(res.data.data.routerLsit)
//   }).then(() => {
//       var routers = [...store.state.routerList];
//       for (let router of routers) {
//         let component = components[router.component];
//         router.component = component;
//       }
//       router.addRoutes(routers);
//   })
// })

export default new Router({
  routes: [
    {
      path: '/',
      name: 'login',
      component: login
    },
    {
      path:'/register',
      name:'register',
      component: register
    },
    {
      path:'/index',
      name:'index',
      component:index
    }
  ]
})
